import React, { useState, useEffect } from 'react';


//  检测 h5 键盘是否弹起  
export function useKeyboardPops() {
  const [screenHeight, setScreenHeight] = useState(document.documentElement.clientHeight);
  const [originHeight] = useState(document.documentElement.clientHeight);
  const [open, setOpen] = useState(false);
  function resize() {
    setScreenHeight(document.documentElement.clientHeight);
  }

  useEffect(() => {
    window.addEventListener('resize', resize);
    return () => {
      window.removeEventListener('resize', resize);
    };
  }, []);

  useEffect(() => {
    if (originHeight > screenHeight + 100) {
      setOpen(false);
    } else {
      setOpen(true);
    }
  }, [screenHeight]);
  return {
    open,
    originHeight,
    screenHeight
  };
}
